package com.jlnk.newdemo.presenter;

import com.jlnk.newdemo.entity.NewsEntity;
import com.jlnk.newdemo.model.NewsModel;
import com.jlnk.newdemo.view.NewsView;
import java.util.List;

public class NewsPresenter {
    private NewsView view;
    private NewsModel model;

    public NewsPresenter(NewsView view) {
        this.view = view;
        this.model = new NewsModel();
    }

    public void loadNewsList(String category) {
        view.showLoading();
        model.getNewsList(category, new NewsModel.NewsListCallback() {
            @Override
            public void onSuccess(List<NewsEntity> newsList) {
                view.hideLoading();
                if (newsList != null && !newsList.isEmpty()) {
                    view.showNewsList(newsList);
                } else {
                    view.showError("No news data available");
                }
            }

            @Override
            public void onFailure(String message) {
                view.hideLoading();
                view.showError(message);
            }
        });
    }
}